﻿using System.Xml;
using Utilities.GlobalData;

namespace Utilities.XmlReader
{
    public static class MyXmlReader
    {
        private const string GENERAL_APP_SETTINGS_XML_PATH = @"Files\XmlSettings\GeneralApplSettings.xml";
        private const string CONSTRAINTS_XML_PATH = @"Files\XmlSettings\Constraints.xml";

        public static void ChangeSingleConstraint(eConstraints constarint, string val)
        {
            string newValue = string.Empty;
            XmlDocument xmlDoc = new XmlDocument();
            xmlDoc.Load(CONSTRAINTS_XML_PATH);
            XmlNode node = xmlDoc.SelectSingleNode(string.Format("/constraints/cons[name='{0}']/value", constarint.ToString()));
            node.InnerText = val;
            xmlDoc.Save(CONSTRAINTS_XML_PATH);
        }

        public static string GetValueOfSingleConstraint(eConstraints constarint)
        {
            XmlDocument xmlDoc = new XmlDocument();
            xmlDoc.Load(CONSTRAINTS_XML_PATH);
            XmlNode node = xmlDoc.SelectSingleNode(string.Format("/constraints/cons[name='{0}']/value", constarint.ToString()));
            return node.InnerText;
        }

        public static string GetValueOfGeneralSetting(eGeneralSettingName generalSettingName)
        {
            XmlDocument xmlDoc = new XmlDocument();
            xmlDoc.Load(GENERAL_APP_SETTINGS_XML_PATH);
            XmlNode node = xmlDoc.SelectSingleNode(string.Format("/GeneralSettings/Setting[name='{0}']/value", generalSettingName.ToString()));
            return node.InnerText;
        }

        public static void ChangeSingleValueOfGeneralSetting(eGeneralSettingName generalSettingName, string val)
        {
            XmlDocument xmlDoc = new XmlDocument();
            xmlDoc.Load(GENERAL_APP_SETTINGS_XML_PATH);
            XmlNode node = xmlDoc.SelectSingleNode(string.Format("/GeneralSettings/Setting[name='{0}']/value", generalSettingName.ToString()));
            node.InnerText = val;
            xmlDoc.Save(GENERAL_APP_SETTINGS_XML_PATH);
        }
    }
}
